package com.hdsx.jxcsxm.log.strategy.impl;

import com.hdsx.jxcsxm.log.bean.SysLog;
import com.hdsx.jxcsxm.log.strategy.IOperatStrategy;
import com.hdsx.jxcsxm.log.type.BusinessType;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import org.apache.struts2.dispatcher.HttpParameters;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 占贤银
 * time 2023/8/18 13:55
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public class LoginOperatStrategy implements IOperatStrategy {


    @Override
    public SysLog operate(ActionInvocation invocation,
                          HttpServletRequest request) {
        // session.getAttribute("unit")
        SysLog sysLog = new SysLog();
        ActionContext ac = invocation.getInvocationContext();
        HttpParameters parameters = ac.getParameters();
        String opt_url = request.getRequestURI();
        String opt_ip = request.getRemoteAddr();
        final String requestMethod = request.getMethod();
        sysLog.setModule("0000");
        sysLog.setTitle(BusinessType.LOGIN_TYPE.getMsg());
        sysLog.setOpt_type(BusinessType.LOGIN_TYPE.getMsg());
        sysLog.setBusiness_type(BusinessType.LOGIN_TYPE.getState());
        sysLog.setMethod(invocation.getInvocationContext().getName());
        sysLog.setRequest_method(requestMethod);
        sysLog.setOpt_url(opt_url);
        sysLog.setOpt_ip(opt_ip);
        sysLog.setOpt_name(parameters.get("master.truename").toString());
        sysLog.setOpt_param(parameters.toString());
        return sysLog;
    }
}
